const CompressionWebpackPlugin = require('compression-webpack-plugin');
const path = require('path');
const pxToRem = require('postcss-pxtorem');

const resolvePath = (dir) => path.join(__dirname, dir);

module.exports = {
  lintOnSave: false,
  productionSourceMap: false,
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          pxToRem({
            rootValue: 37.5, // UI设计图宽度 / 10
            propList: ['*'],
          }),
        ],
      },
    },
  },
  configureWebpack: (config) => {
    // 设置路径别名
    config.resolve.alias = {
      '@': resolvePath('src'),
      _c: resolvePath('src/components'),
      _a: resolvePath('src/assets'),
    };

    // 事先将源文件压缩成.gz文件，减轻Nginx服务器的压力
    config.plugins.push(
      new CompressionWebpackPlugin({
        test: /\.(js|css|html)$/,
      })
    );
  },
};
